﻿//-----------------------------------------------------------------------
// <copyright file="ValidationService.cs" company="FastNET Services">
//     Copyright (c) 2007-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings
using System.Collections.Generic;
using FastNET.CleanAct.Client.Interfaces.Jobs;
using FastNET.CleanAct.Client.Interfaces.Services;
using FastNET.CleanAct.Client.Interfaces.TaskProcessing.Validators;
using FastNET.CleanAct.Client.Interfaces.Tasks;
using FastNET.CleanAct.Client.TaskProcessing.Basic.Validators;

#endregion

namespace FastNET.CleanAct.Client.ClientEngine.Managers.Processing.Services
{
    internal class ValidationService : IService
    {
        #region Variables

        private readonly List<IValidator> _validators;

        #endregion

        #region CTor/DTor

        /// <summary>
        /// Initializes a new instance of the ValidationService class
        /// </summary>
        public ValidationService()
        {
            _validators = new List<IValidator>
                          {
                            new FileSystemValidator(),
                            new RegistryValidator()
                          };
        }

        #endregion

        #region Public Collection Properties

        /// <summary>
        /// Gets or sets the list of all jobs that can be processed by the service
        /// </summary>
        public List<IJob> JobList { get; set; }

        #endregion

        #region Public Processing Methods

        /// <summary>
        /// Tells the service to process the list of jobs
        /// </summary>
        public void Process()
        {
            foreach (IJob job in JobList)
            {
                foreach (ITask task in job.TaskList)
                {
                    foreach (IValidator validator in _validators)
                    {
                        if (!validator.CompatibleTaskTypes.Contains(task.GetType()))
                        {
                            continue;
                        }

                        job.ProcessedBy.Add(string.Format("{0} - {1}", validator.ProcessorName, validator.ProcessorDescription));
                        validator.ValidateTask(task);
                    }
                }
            }
        }

        #endregion
    }
}
